package com.bw.zg3park2212.device

import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.bw.base.entity.DeviceAddParam
import com.bw.base.mvvm.BaseActivity
import com.bw.zg3park2212.databinding.ActivityDeviceXiangBinding
import dagger.hilt.android.AndroidEntryPoint

@Route(path = "/app/DeviceXiangActivity")
@AndroidEntryPoint
class DeviceXiangActivity : BaseActivity<ActivityDeviceXiangBinding,DeviceViewModel>() {
    @Autowired
    @JvmField
    var dxid="63"
    override fun intitView() {
        ARouter.getInstance().inject(this)
        viewmodel.getDeviceXiang(dxid.toInt())

    }

    override fun intitData() {
        viewmodel.devicexiangSuccse.observe(this){
            binding.deviceName.text=it.deviceName
            binding.deviceType.text=it.deviceType
            binding.failureRate.text=""+(it.failureRate*100)+"%"
            binding.installationLocation.text=it.installationLocation
            binding.btn1.setOnClickListener {it1->
                if (it.status=="正常"){
                    val deviceAddParam=DeviceAddParam()
                    deviceAddParam.deviceName=it.deviceName+"ABC"
                    deviceAddParam.deviceType=it.deviceType+"ABC"
                    deviceAddParam.failureRate=it.failureRate
                    deviceAddParam.installationLocation=it.installationLocation+"ABC"
                    deviceAddParam.status="故障"
                    viewmodel.getDeviceUpdate(dxid.toInt(),deviceAddParam)
                }
            }
            binding.btn2.setOnClickListener {it1->
               if (it.status=="故障"){
                   val deviceAddParam=DeviceAddParam()
                   deviceAddParam.deviceName=it.deviceName+"ABC"
                   deviceAddParam.deviceType=it.deviceType+"ABC"
                   deviceAddParam.failureRate=it.failureRate
                   deviceAddParam.installationLocation=it.installationLocation+"ABC"
                   deviceAddParam.status="正常"
                   viewmodel.getDeviceUpdate(dxid.toInt(),deviceAddParam)
               }
            }
        }
        viewmodel.deviceupdateSuccse.observe(this){
            ToastUtils.showLong("修改成功")
            finish()
        }
    }

}